//
//  LocationDelegate.m
//  Terperature
//
//  Created by Aaron Cordova on 12/10/08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "LocationDelegate.h"

static LocationDelegate *sharedDelegate = nil;

@implementation LocationDelegate

@synthesize locManager;

- (id) init {
    self = [super init];
    if (self != nil) {
        self.locManager = [[[CLLocationManager alloc] init] autorelease];
        self.locManager.delegate = self;
    }
    return self;
}

// use location update
- (void)locationManager:(CLLocationManager *)manager 
    didUpdateToLocation:(CLLocation *)newLocation 
           fromLocation:(CLLocation *)oldLocation {
    
    NSLog(@"got location update");
    
    UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Update" message:@"got location" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertView show];
    [alertView release];
    
    // don't need continuous updates
    [locManager stopUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
    UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Update" message:@"location error" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertView show];
    [alertView release];
}

+ (LocationDelegate *)sharedInstance {
    @synchronized(self) {
        if (sharedDelegate == nil) {
            sharedDelegate = [[self alloc] init];
        }
        return sharedDelegate;
    }
}

@end
